package com.xkdx.caipiao.util;

import java.util.ArrayList;
import java.util.List;

import com.xkdx.caipiao.pubclass.SelectCode;
import com.xkdx.caipiao.statics.IConstants;

public class CaipiaoUtil {
	public static String BAIWAN = "baiwan";
	public static String SHIWAN = "shiwan";
	public static String WAN = "wan";
	public static String QIAN = "qian";
	public static String BAI = "bai";
	public static String SHI = "shi";
	public static String GE = "ge";

	public static String getCaiPiaoString(ArrayList<SelectCode> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			String redcode = list.get(i).getRedCode().trim().replace(" ", "#");
			String[] str = redcode.split("#");
			for (int j = 0; j < str.length; j++) {

				if (str[j].toCharArray().length > 1) {
					StringBuffer sb2 = new StringBuffer();
					char[] ch = str[j].toCharArray();
					for (int k = 0; k < ch.length; k++) {
						if (k < ch.length - 1) {
							sb2.append(ch[k] + ",");
						} else {
							sb2.append(ch[k]);
						}
						str[j] = sb2.toString();
					}
				}
				sb.append(str[j]).append("#");
			}
			sb.setLength(sb.length() - 1);
			sb.append("@");
		}
		sb.setLength(sb.length() - 1);
		return sb.toString();

	}

	public static List<String> ChooseSix(String[] a, int num) {
		List<String> list = new ArrayList<String>();
		StringBuffer sb = new StringBuffer();
		String[] b = new String[a.length];
		for (int i = 0; i < b.length; i++) {
			if (i < num) {
				b[i] = "1";
			} else
				b[i] = "0";
		}

		int point = 0;
		int nextPoint = 0;
		int count = 0;
		int sum = 0;
		String temp = "1";
		while (true) {
			// 判断是否全部移位完毕
			for (int i = b.length - 1; i >= b.length - num; i--) {
				if (b[i].equals("1"))
					sum += 1;
			}
			// 根据移位生成数据
			for (int i = 0; i < b.length; i++) {
				if (b[i].equals("1")) {
					point = i;
					sb.append(a[point]);
					sb.append(" ");
					count++;
					if (count == num)
						break;
				}
			}
			// 往返回值列表添加数据
			list.add(sb.toString());

			// 当数组的最后num位全部为1 退出
			if (sum == num) {
				break;
			}
			sum = 0;

			// 修改从左往右第一个10变成01
			for (int i = 0; i < b.length - 1; i++) {
				if (b[i].equals("1") && b[i + 1].equals("0")) {
					point = i;
					nextPoint = i + 1;
					b[point] = "0";
					b[nextPoint] = "1";
					break;
				}
			}
			// 将 i-point个元素的1往前移动 0往后移动
			for (int i = 0; i < point - 1; i++)
				for (int j = i; j < point - 1; j++) {
					if (b[i].equals("0")) {
						temp = b[i];
						b[i] = b[j + 1];
						b[j + 1] = temp;
					}
				}
			// 清空 StringBuffer
			sb.setLength(0);
			count = 0;
		}
		//
		System.out.println("数据长度 " + list.size());
		return list;

	}

}